package mobilesafe.guoshisp.com.xdtong.net;

import android.os.Handler;
import android.os.Message;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.IOException;

import mobilesafe.guoshisp.com.xdtong.model.Const;

/**
 * Description:发送httpGet网络线程类
 * User: Dream_Coder(chenchen_839@126.com)
 * Date: 2015-07-19
 * Time: 00:28
 */
public class ThreadHttpGet implements Runnable{

    private String url;/*发送请求的url*/
    private HandleNetCallBack mCallBack;

    public ThreadHttpGet(String url,HandleNetCallBack callBack) {
        this.url = url;
        this.mCallBack = callBack;
    }
    @Override
    public void run() {
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);
        Message msg = Message.obtain();
        try {
            HttpResponse httpResponse = httpClient.execute(httpGet);
            if(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK ||
                    httpResponse.getStatusLine().getStatusCode()== HttpStatus.SC_MOVED_TEMPORARILY) {
                mCallBack.OnSuccess(httpResponse);
            }else {
                mCallBack.OnFail(httpResponse);
            }
            httpGet.abort();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
